///////////////////////////////////////////////////////////////////////
//  CS 3715 (Winter 2012), Final Project                      		 //
//  Program File Name: Server.java                     				 //
//       Student Name: Jonathan Hart-Wall, Kenny Hardiman            //
//         Login Name: jcwhw1, kch004                                //
//              MUN #: 200933455, 200930253    						 //
///////////////////////////////////////////////////////////////////////

package ca.FMP;

import org.mortbay.jetty.Handler;
import org.mortbay.jetty.handler.*;
import org.mortbay.jetty.servlet.Context;

/**
 * Server Class.
 * Creates Jetty Server at port 8888
 *
 */
public class Server {
	public static void main(String[] args) throws Exception {
		int port = 8888;
		String baseDir = ".";
		
		/**
		 * Loop to set Jetty Server port
		 */
		if (args.length == 2 ) {
			port = Integer.parseInt(args[0]);
			baseDir = args[1];
		} 
		else if (args.length == 1 ) {
			port = Integer.parseInt(args[0]);
		}
		
		
		/**
		 * Creates Jetty server
		 */
		org.mortbay.jetty.Server JetServ = new org.mortbay.jetty.Server(port);
		
		ResourceHandler rh = new ResourceHandler();
		rh.setResourceBase(baseDir);
		
		ContextHandlerCollection c = new ContextHandlerCollection();
		Context servlets = new Context(c,"/");
		servlets.addServlet(PizzaPlaceServlet.class, "/PizzaPlaces");
		servlets.addServlet(OrderServlet.class, "/Order");
		servlets.addServlet(PizzaServlet.class, "/Pizza");
		
		JetServ.addHandler(rh);
		JetServ.addHandler(c);
		JetServ.addHandler(new DefaultHandler());
		
		JetServ.start();
		JetServ.join();
	}

}

